<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of productive_lines_controller
 *
 * @author wilavel
 */
class ProductiveLinesController extends AppController {

    //put your code here
    var $name = "ProductiveLines";

    public function index($evaluation_id) {
        $this->set('evaluation_id', $evaluation_id);
        $this->ProductiveLine->recursive = 0;
        $this->set('lineas', $this->ProductiveLine->find('all', array('conditions' => array('ProductiveLine.initial_evaluation_id' => $evaluation_id), 'fields' => array('ProductiveLine.id', 'ProductiveLine.rendimientos_calificacion', 'ProductiveLine.costos_calificacion', 'ProductiveLine.precios_venta_calificacion', 'ProductiveActivity.nombre', 'InitialEvaluation.cerrado'))));
    }

    public function credit_index($evaluation_id) {
        $this->set('evaluation_id', $evaluation_id);
        $this->set('lineas', $this->ProductiveLine->find('all', array('conditions' => array('ProductiveLine.initial_evaluation_id' => $evaluation_id), 'fields' => array('ProductiveLine.id', 'ProductiveLine.credito_calificacion', 'ProductiveLine.credito_concepto', 'ProductiveLine.credito_valor', 'ProductiveActivity.nombre', 'InitialEvaluation.cerrado'))));
    }

    public function add($evaluation_id) {
        $this->set('evaluation_id', $evaluation_id);
        $this->set('productiveActivities', $this->ProductiveLine->ProductiveActivity->find('list', array('fields' => array('ProductiveActivity.id', 'ProductiveActivity.nombre'))));
        if (!empty($this->data)) {
            if ($this->ProductiveLine->saveAll($this->data)) {
                $this->Session->setFlash('Registro guardado con éxito', 'flash_custom');
                $this->redirect(array('controller' => 'ProductiveLines', 'action' => 'index', $evaluation_id));
            }
        }
    }

    public function edit($line_id, $evaluation_id) {
        $this->set('evaluation_id', $evaluation_id);
        $this->set('productiveActivities', $this->ProductiveLine->ProductiveActivity->find('list', array('fields' => array('ProductiveActivity.id', 'ProductiveActivity.nombre'))));

        if (empty($this->data)) {
            $this->ProductiveLine->recursive = -1;
            $this->data = $this->ProductiveLine->find('first', array('conditions' => array('ProductiveLine.id' => $line_id)));
            $this->set('actividad', $this->ProductiveLine->ProductiveActivity->find('first', array('fields' => array('ProductiveActivity.id', 'ProductiveActivity.tipo'), 'conditions' => array('ProductiveActivity.id' => $this->data['ProductiveLine']['productive_activity_id']))));
        } else {
            if ($this->ProductiveLine->saveAll($this->data)) {
                $this->Session->setFlash('Registro editado con éxito', 'flash_custom');
                $this->redirect(array('controller' => 'ProductiveLines', 'action' => 'index', $evaluation_id));
            }
        }
    }

    public function credit_edit($line_id, $evaluation_id) {
        $this->set('evaluation_id', $evaluation_id);
        if (empty($this->data)) {
            $this->ProductiveLine->recursive = -1;
            $this->data = $this->ProductiveLine->find('first', array('conditions' => array('ProductiveLine.id' => $line_id)));
        } else {
            if ($this->ProductiveLine->saveAll($this->data)) {
                $this->Session->setFlash('Registro editado con éxito', 'flash_custom');
                $this->redirect(array('controller' => 'ProductiveLines', 'action' => 'credit_index', $evaluation_id));
            }
        }
    }

    public function delete($line_id, $evaluation_id) {
        if ($this->ProductiveLine->delete($line_id)) {
            $this->Session->setFlash('Registro borrado con éxito', 'flash_custom');
            $this->redirect(array('controller' => 'ProductiveLines', 'action' => 'index', $evaluation_id));
        }
    }

    public function select() {
        $this->set('actividad', $this->ProductiveLine->ProductiveActivity->find('first', array('fields' => array('ProductiveActivity.id', 'ProductiveActivity.tipo'), 'conditions' => array('ProductiveActivity.id' => $this->data['ProductiveLine']['productive_activity_id']))));
    }

}

?>
